<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!doctype html>
<html>
<head>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;消息处理</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content">
			<button type="button" class="btn dpbtn_green" onclick="add();">新增</button>
		</div>
		<div class="ibox-content">
			<div role="form" class="form-inline">
               <input type="text" placeholder="请输消息事件" id="typeMsgEventQuery" class="form-control">
               <button class="zhixcx" type="button" onclick="query();">执行查询</button>
        	</div>
        </div>
		<div class="ibox-content">
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>
	<div class="contractDiv" id="contractDiv" style="display: none;">
		<div class="business-padding">
			<table cellpadding="0" cellspacing="0" border="0"
				class="buyinfor-table">
				<tr>
					<td align="right"><label class="control-label np">消息类型：</label>
					</td>
					<td><select id="typeMsgEvent" name="typeMsgEvent" class="select-control"></select></td>
				</tr>
				<tr>
					<td align="right" valign="top"><label class="control-label np">消息状态：</label>
					</td>
					<td class="statusMsgHandleTd"> </td>
				</tr>
			</table>
		</div>
		<div class="business-padding">
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr>
					<td width="100%" align="center">
						<div class="ibox-content">
							<button class="btn dpbtn_green" type="button" onclick="dkszsave();">确定</button>
							<button class="btn dpbtn_red" type="button" onclick="dkszcancel();">取消</button>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>

	<div class="contractDiv" id="contractDivb" style="display: none;">
		<div class="business-padding">
			<input type="hidden" id="id" />
			<table cellpadding="0" cellspacing="0" border="0"
				class="buyinfor-table">
				<tr>
					<td align="right"><label class="control-label np">消息类型：</label>
					</td>
					<td><select id="typeMsgEventb" name="typeMsgEvent" class="select-control" disabled="disabled"></select></td>
				</tr>
				<tr>
					<td align="right" valign="top"><label class="control-label np">消息状态：</label>
					</td>
					<td class="statusMsgHandleTdb"> </td>
				</tr>
			</table>
		</div>
		<div class="business-padding">
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr>
					<td width="100%" align="center">
						<div class="ibox-content">
							<button class="btn dpbtn_green" type="button" onclick="dkszupdate();">确定</button>
							<button class="btn dpbtn_red" type="button" onclick="dkszcancel();">取消</button>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>
	<!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
	<script type="text/javascript">
	    
	    var winWidth = $(window).width();
		var winHeight = $(window).height();
	    jQuery(function($) {  
	    	getData();
	    });
	    
	    $(function(){
			$.dpAjax({
				show:false,
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{"parentValue":"MessageEventType"},
	 			success: function(datas){
	 					  var result = datas.result.rows;
	 					  var programme_sel=[];
	 				      for(var i=0;i<result.length;i++){
	 				          var programme = result[i];
	 				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
	 				      }
	 				     $("#typeMsgEvent").html(programme_sel.join(' '));
	 				     $("#typeMsgEventb").html(programme_sel.join(' '));
	              }
		    	});
			
			$.dpAjax({
				show:false,
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{"parentValue":"MessageHandleStatus"},
	 			success: function(datas){
 					  var result = datas.result.rows;
 					  var html='';
 				      for(var i=0;i<result.length;i++){
 				          var programme = result[i];
 				          html += '<label style="display:block;width:100%; margin-top:8px;"><input type="checkbox" name="statusMsgHandle" value="'+programme.value+'" />'+programme.name+'</label>';
 				      }
 				     $(".statusMsgHandleTd").html(html);
 				     $(".statusMsgHandleTdb").html(html);
	              }
		    	});
		 });
	    
	    var updatelayer;
	    var getData = function()
	    {
	  var winWidth = $('div.ibox-content').width();
	        winHeight = document.body.offsetHeight - 350;
	       var win = winWidth / 7 - 20;
  	 	   $.jgrid.defaults.styleUI = 'Bootstrap';
  	 	   
		  jQuery("#table_list_1").jqGrid
		  ({
			url:'${basePath}/OtherMessageHandleController/selectMulitList',
	        datatype : "json",
	        colNames : [ '主键', '', '','多个消息状态CODE','消息事件','消息状态'],
	        colModel : [ 
	                     {name: 'replaceId', index: 'id', hidden:true},
	            		 {name: 'typeMsgEvent', hidden:true},
	            		 {name: 'statusMsgHandle', hidden:true},
	            		 {name: 'statusMsgHandles', hidden:true},
	            		 {name: 'typeMsgEventDisplay',index: 'typeMsgEventDisplay',width: win,align: "center"},
	            		 {name: 'statusMsgHandleDisplay',index: 'statusMsgHandleDisplay',width: win,align: "center"}
	                   ],
              mtype : "post",
              height: winHeight,
              width:winWidth,  
              autowidth: true,
              shrinkToFit: true,
              rowNum: 15,
              rowList: [15, 30, 45],
              viewrecords: true,
              pager: "#pager_list_1",
              sortorder : "desc",
              sortname : 'created',
              hidegrid: false,
              multiselect : false,
              altRows:true,
              altclass:'someClass',
              ondblClickRow:function(rowId,v,e)
              {	
            	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
                  var id = rowData.replaceId;
                  var typeMsgEventb = rowData.typeMsgEvent;
                  var statusMsgHandles = rowData.statusMsgHandles;
                  document.getElementById("id").value=id;
                  document.getElementById("typeMsgEventb").value=typeMsgEventb;
                  
                  updatelayer=layer.open({
         				  title:'修改',
         				  type: 1,
         				  area: ['350px', '300px'], //宽高
         				  content: $('#contractDivb'),
         				  end:function(){
         					 $('.statusMsgHandleTdb input[name="statusMsgHandle"]').removeAttr('checked');
         				  }
         			});
                  
	              $('.statusMsgHandleTdb input[name="statusMsgHandle"]').each(function(index){
	   				   if(statusMsgHandles.indexOf(this.value) >= 0){
	   					   this.checked = true;
	   				   }
	   			  });
              },
              jsonReader : {
            	  root:"result.rows",
            	  page: "result.page",
            	  total: "result.total",
            	  records: "result.records",
            	  repeatitems: false,
            	  id: "replaceId"
              },
              loadComplete:function(datas){
            	  if (datas.flag == "100100") {
                      layer.msg("查询成功!", {icon: 6, time: 1000});
                      return;
                  }
            	  if(datas.flag == '100802') {
    				  top.location.href = thisLoginUrl;
    				  return;
    			  }

            	  layer.msg(datas.message, {icon: 2});
              }
	      });
	    }
	    
	    var addlayer;
	    var add=function(){
	    	addlayer=layer.open({
				  title:'新增',
				  type: 1,
				  area: ['350px', '350px'], //宽高
				  content: $('#contractDiv')
			});
	    }
	    var dkszsave=function(){
	    	var data={};
	    	
	    	data.typeMsgEvent=$('#typeMsgEvent option:selected').val();
	    	
	    	var value ="";//定义一个数组      
	        $('.statusMsgHandleTd input[name="statusMsgHandle"]:checked').each(function(){//遍历每一个名字为id的复选框，其中选中的执行函数      
	        	value+=$(this).val()+",";//将选中的值添加value中，以逗号分开     
	        });
	    	
	       /*  var length = value.length;
	    	if(length == 0){
	    		layer.msg('至少选择一个消息状态！', {icon: 5});
	    		return;
	    	}
	    	 */
	    	data.statusMsgHandle = value;
	    	
	    	$.dpAjax({
	    		url:'${basePath}/OtherMessageHandleController/save',
    			data:data,
    			success: function(datas){
    				layer.msg('执行成功！', {icon: 6});
				    layer.close(addlayer);
				    refresh();
				    return;
    			} 
	    	});
	    }
	    var dkszupdate=function(){
	    	var data={};
	    	data.id=$("#id").val();
	    	
	    	data.typeMsgEvent=$('#typeMsgEventb option:selected').val();
	    	
	    	var value ="";//定义一个数组      
	        $('.statusMsgHandleTdb input[name="statusMsgHandle"]:checked').each(function(){//遍历每一个名字为id的复选框，其中选中的执行函数      
	        	value+=$(this).val()+",";//将选中的值添加value中，以逗号分开     
	        });
	    	
	    	var length = value.length;
	    	if(length == 0){
	    		layer.msg('至少选择一个消息状态！', {icon: 5});
	    		return;
	    	}
	    	data.statusMsgHandle = value;
	    	
	    	$.dpAjax({
	    		url:'${basePath}/OtherMessageHandleController/modify',
    			data:data,
    			success: function(datas){
    			  if(datas.flag == "100100"){
						  layer.msg('执行成功！', {icon: 6});
						  layer.close(updatelayer);
						  refresh();
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
					  if(datas.flag=="101102"){
						  layer.msg('执行失败，消息类型已存在！', {icon: 5});
	                	  return;
					  }
                }
	    	});
	    }
	    window.onresize = function()
	    {
	    	$("#table_list_1").setGridWidth($(window).width()-80);
	    }
	    
	    
	    var refresh = function()
	    {
	    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", []);
	    }
	    
	    function dkszcancel(){
	    	layer.closeAll();
	    }
	    
	    var query = function()
	    {
	    	var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
	    	var typeMsgEventQuery = document.getElementById('typeMsgEventQuery').value || '';
	    	$.extend(postData, { "typeMsgEventDisplay" : typeMsgEventQuery.trim()});
	    	refresh();
	    }
    </script>
</body>
</html>
